const router = require('koa-router')({
    prefix: '/image'
});
const request = require('request');


router.get('/avatar', async (ctx, next)=>{
    const width = ctx.query.width || 250;
    const randomNumber = Math.random() * 100000000;
    const avatar = await request.get(`https://api.adorable.io/avatars/${width}/${randomNumber}.png`);
    ctx.body = avatar;
});

router.get('/avatar/:identifier', async (ctx, next)=>{
    const width = ctx.query.width || 250;
    const {identifier} = ctx.params;
    const avatar = await request.get(`https://api.adorable.io/avatars/${width}/${identifier}.png`);
    ctx.body = avatar;
});

module.exports = router;